unit PubDlgFunc;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, ExtCtrls;
const
  MSG_Root = WM_USER + 1000;
  MSG_SYS_PROGRESSBAR = MSG_ROOT + 25;
function ShowProgressDlg(const Title,ACaption: string;StepCount: Integer): Boolean;
procedure StepProgressDlg(const Steps: Integer);
function GetCompleteParts: Integer;
procedure UpdateProgressDlgPosition(const APosition: Integer);
procedure UpdateProgressDlg(const ACaption: string);
procedure CloseProgressDlg;

implementation

uses Progress;


var DlgProgress: TfrmProgress = nil;

function ShowProgressDlg(const Title,ACaption: string;StepCount: Integer): Boolean;
begin
  //PostMessage(Application.Handle, MSG_SYS_PROGRESSBAR,0,0);
  if not Assigned(DlgProgress) then
    DlgProgress := TfrmProgress.Execute;
  if Assigned(DlgProgress) then
    DlgProgress.UpdateInfo(Title,ACaption,StepCount);
  Result := Assigned(DlgProgress);
end;

procedure CloseProgressDlg;
begin
  if Assigned(DlgProgress) then
  begin
    DlgProgress.Close;
    FreeAndNil(DlgProgress);
  end;
  //PostMessage(Application.Handle, MSG_SYS_PROGRESSBAR,1,0);
end;

procedure UpdateProgressDlg(const ACaption: string);
begin
  if Assigned(DlgProgress) then
    DlgProgress.UpdateInfoA(ACaption);
end;

procedure StepProgressDlg(const Steps: Integer);
begin
  if Assigned(DlgProgress) then
  begin
    DlgProgress.StepIt(Steps);
  end
end;

function GetCompleteParts: Integer;
begin
  if Assigned(DlgProgress) then
    Result := DlgProgress.CompleteParts
end;

procedure UpdateProgressDlgPosition(const APosition: Integer);
begin
  if Assigned(DlgProgress) then
//    if APosition < DlgProgress.ProgressBar1 then
    DlgProgress.ProgressBar.Position := APosition;
    //DlgProgress.ProgressBar1.PercentCompla := APosition;
end;



end.
